function autoScale(selector, options) {
    var el = document.querySelector(selector)
    var { width, height } = options

    el.style.transformOrigin = "top left"

    function init() {
        var scaleX = innerWidth / width
        var scaleY = innerHeight / height
        scale = Math.min(scaleX, scaleY)

        var left = (innerWidth - width * scale) / 2
        var top = (innerHeight - height * scale) / 2

        el.style.transform = `translate(${left}px, ${top}px) scale(${scale})`
    }

    init()

    window.addEventListener("resize", init)
}

document.addEventListener("DOMContentLoaded", function () {
    // 页面加载完成，DOM 树已构建
    autoScale("body", {
        width: 1920,
        height: 1080
    })
});
